import axios from "axios";
import { ElMessage } from 'element-plus'

// 参数默认类型
axios.defaults.headers['Content-Type'] = 'application/json;'
axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'

// create an axios instance
const service = axios.create({
    // baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
    // withCredentials: true, // send cookies when cross-domain requests
    timeout: 10000 // request timeout
  })


  service.interceptors.request.use(
  config => {
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);
// response interceptor 响应拦截器
service.interceptors.response.use(
  response => {
    if (response.status == 200) {
      return Promise.resolve(response);
    } else {
      return Promise.reject(response);
    }
  },
  error => {
    ElMessage({
      type: 'error',
      message: error.message,
      duration: 5 * 1000
    });
  }
);
export default service